<template>
  <div>
    <p>你的积分还有:{{ jifen }}</p>

    <table border="1" cellspacing="0">

      <tr>
        <td>礼品</td>
        <td>所需积分</td>
        <td>操作</td>

      </tr>
      <tr v-for="i in lipin" :key="i.id">
        <td>{{ i.name }}</td>
        <td>{{ i.money }}</td>
        <td>
          <van-button @click="duihuan(i.id)">兑换</van-button>

        </td>

      </tr>
    </table>

  </div>
</template>

<script>
import axios from "axios";


export default {
  name: "dh_lipin",
  data() {
    return {
      lipin: [],
      jifen: 0,
      userid: localStorage.getItem('userid')
    }
  },
  methods: {
    show_lipin() {
      axios.get('/zuoye/lipin').then(res => {
        if (res.data.code == 200) {
          this.lipin = res.data.list
        }
      })
    },
    duihuan(id) {
      axios.put('/zuoye/lipin', {'id': id, 'userid': this.userid})
          .then(res => {
            if (res.data.code == 200) {
              alert('兑换成功')
              this.get_jifen()
            } else {
              alert(res.data.mes)
            }
          })
    },
    get_jifen() {
      axios.get('/zuoye/jifen?userid=' + this.userid).then(res => {
        this.jifen = res.data.jifen
      })
    }


  },
  mounted() {
    this.show_lipin()
    this.get_jifen()

  }
}
</script>

<style scoped>

</style>